//
//  NYSettingViewController.m
//  Nooryes
//
//  Created by baken on 2020/3/1.
//  Copyright © 2020 MyApp. All rights reserved.
//

#import "NYSettingViewController.h"
#import "WebViewController.h"
#import "NYAlertView.h"
#import "NYLoginViewModel.h"
#import "NYBindListModel.h"

@interface NYSettingViewController ()
@property (weak, nonatomic) IBOutlet UILabel *qqLabel;
@property (weak, nonatomic) IBOutlet UILabel *wechatLabel;
@property (nonatomic, strong) NYLoginViewModel *loginVM;

@end

@implementation NYSettingViewController


-(NYLoginViewModel *)loginVM{
    if (!_loginVM) {
        _loginVM = [NYLoginViewModel new];
    }
    return _loginVM;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self.loginVM getThr3BindListWithCompletionHandle:^(NSError *error) {
        if (!error) {
            for (BindListModel *model in self.loginVM.bindArray) {
                if (model.type ==1) {
                    self.qqLabel.text = @"已绑定";
                } else{
                    self.wechatLabel.text = @"已绑定";
                }
            }
        }
    }];
}


- (IBAction)onBindWechat:(id)sender {
    self.loginVM.loginPlatform = @"2";
    [self.loginVM bindThr3WithCompletionHandle:^(NSError *error) {
        NYAlertView *alert =[[NYAlertView alloc] init];
        if (!error) {
            self.qqLabel.text = @"已绑定";
            alert.title = @"绑定成功";
        } else {
            alert.title = [error localizedDescription];
        }
        
        [alert showAlert:^{}];
    }];
}

- (IBAction)onBindQQ:(id)sender {
    self.loginVM.loginPlatform = @"1";
    [self.loginVM bindThr3WithCompletionHandle:^(NSError *error) {
        NYAlertView *alert =[[NYAlertView alloc] init];
        if (!error) {
            self.qqLabel.text = @"已绑定";
            alert.title = @"绑定成功";
        } else {
            alert.title = [error localizedDescription];;
        }
        
        [alert showAlert:^{}];
    }];
}


- (IBAction)onClearCache:(id)sender {
    UIAlertController *alertVC = [UIAlertController alertControllerWithTitle:@"清理缓存" message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
    }]];
    [alertVC addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        NYAlertView *alert =[[NYAlertView alloc] init];
        alert.title = @"清理完成";
        [alert showAlert:^{ }];
    }]];
    
    
    [self presentViewController:alertVC animated:true completion:nil];
}
- (IBAction)onFeedback:(id)sender {
    
}

- (IBAction)onAbout:(id)sender {

    WebViewController *webVC = [[WebViewController alloc] init];
    webVC.urlString = myDelegate.aboutUrl;

    [self.navigationController pushViewController:webVC animated:YES];
}

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
    UIViewController *destination = segue.destinationViewController;
    if ([destination respondsToSelector:@selector(setPhone:)]) {
        [destination setValue:self.phone forKey:@"phone"];
    }
}

- (IBAction)onLogout:(id)sender {
    [self.loginVM logoutWithCompletionHandle:^(NSError *error) {
        
        [self.navigationController popViewControllerAnimated:YES];
        
    }];
}

- (IBAction)onBlackList:(id)sender {
    
}

@end
